<?php

namespace Admin\Factory;
use Zend\Db;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\Hydrator;
use Admin\Mapper;
use User\Options;

class AdminUserMapperFactory implements  FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $options = $serviceLocator->get('admin_module_options');
        /* @var $dbAdapter Db\Adapter\Adapter */
        $dbAdapter = $serviceLocator->get('user_zend_db_adapter');

        $mapper = new Mapper\AdminUser();
        $mapper->setDbAdapter($dbAdapter);


        $entityClass = $options->getUserEntityClass();
        /* @var $hydrator Hydrator\HydratorInterface */
        $hydrator = $serviceLocator->get('user_hydrator');

        $mapper
            ->setEntityPrototype(new $entityClass)
            ->setHydrator($hydrator)
            ->setTableName($options->getTableName())
        ;

        return $mapper;
    }
} 